package com.android.mensa;

import android.app.Activity;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;

import com.android.mensa.providers.MenuProvider;

public class SplashScreen extends Activity {

	private DownloadMenuTask mTask;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.splashscreen);

		mTask = new DownloadMenuTask();
		mTask.execute((Void[]) null);
	}

	@Override
	public void onBackPressed() {

		if (mTask != null)
			mTask.cancel(true);

		finish();
		super.onBackPressed();
	}

	private class DownloadMenuTask extends AsyncTask<Void, Void, Void> {

		@Override
		protected Void doInBackground(Void... arg0) {
			MenuProvider.getInstance().fetchMenu();
			return null;
		}

		@Override
		protected void onPostExecute(Void result) {
			super.onPostExecute(result);
			finish();
			startActivity(new Intent("com.android.mensa.MainActivity"));
		}
	}
}
